<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="metronic/assets/global/plugins/jquery-1.11.0.min.js" type="text/javascript"></script>
    <link href="metronic/assets/global/plugins/bootstrap/css/bootstrap.min.css" type="text/css"/>
    <link href="metronic/assets/global/css/components.css" rel="stylesheet" type="text/css"/>
    <link href="metronic/assets/admin/pages/css/login.css" rel="stylesheet" type="text/css"/>
</head>
<body class="login">
<div class="content">
    <h3 class="form-title">登录</h3>
    <div class="form-group">
        <label class="control-label">手机号</label>
        <div >
            <input class="form-control" type="text" placeholder="手机号" name="mobile" id="mobile">
        </div>
    </div>

    <div class="form-group">
        <label class="control-label">密码</label>
        <div >
            <input class="form-control" type="password" placeholder="密码" name="password" id="password">
        </div>
    </div>


    <div class="form-actions">
        <button class="btn green" id="login" type="submit">登录</button>
        <button class="btn blue" id="reg" type="submit">注册</button>
    </div>

</div>
<script>
    jQuery(document).ready(function () {

        $("#reg").on("click",function(){
            window.location.href="reg.html"
        })

        $("#login").on("click",function () {
            var mobile=$("#mobile").val()
            if (mobile == null || mobile == "") {
                alert("手机号不能为空")
                return false;
            }
            var password=$("#password").val()
            if (password == null || password == "") {
                alert("密码不能为空")
                return false;
            }
            $.ajax({
                type:"POST",
                contentType:"application/x-www-form-urlencoded",
                url:"http://localhost:8080/user/login",
                data:{
                    "mobile":mobile,
                    "password":password,


                },
                xhrFields:{withCredentials: true},
                success:function (data) {
                    if (data.status == "success") {
                        alert("恭喜"+data.data+"登录成功")
                        window.location.href="list.html"
                    }else{
                        alert("登录失败，原因是"+data.data.errMsg)
                    }
                },
                error:function (data) {  //网络中断时被调用
                    alert("otp获取失败，原因是与服务器网络中断或者"+data.responseText)
                }
            });
        })

    })
</script>
</body>
</html>